<?php
class NewsListAction extends CommonAction {

    public function index() {
        if(isset($_GET['id'])) {
            $mem = parent::useMemcached();
            C('TOKEN_ON',false);
            $news = D('News', 'Admin');
            $newsNav = D('PressNav', 'Admin');
            $navid = $this->_get('id');
            parent::page($news->where('nav='.$navid)->count());

            //显示当前类别
            if(!$mem->get("navname-$navid")) {
                $navName = $newsNav->where('id='.$navid)->getField('name');
                $mem->set("navname-$navid", $navName, MEMCACHE_COMPRESSED, 0);
            } else {
                $navName = $mem->get("navname-$navid");
            }

            //显示当前类别所有文章
            if(!$mem->get("navList-$navid")) {
                $navList = $news->field(array('id', 'title', 'title' => 'ftitle', 'addtime'))
                    ->where('nav=' . $navid)
                    ->limit($this->limit)
                    ->order('addtime DESC')
                    ->select();
                $mem->set("navList-$navid", $navList, MEMCACHE_COMPRESSED, 60);
            } else {
                $navList = $mem->get("navList-$navid");
            }

            //获取本类热门文章
            if(!$mem->get("hotNews-$navid")) {
                $hotNews = $news->field(array('id', 'title', 'title' => 'ftitle', 'addtime'))
                    ->where('nav=' . $navid)
                    ->limit(8)
                    ->order('view_count DESC')
                    ->select();
                $mem->set("hotNews-$navid", $navList, MEMCACHE_COMPRESSED, 60);
            } else {
                $hotNews = $mem->get("hotNews-$navid");
            }

            //获取本类推荐文章
            $map['attr'] = array('like', '%推荐%');
            $map['nav'] = array('eq', $navid);

            if(!$mem->get("recList-$navid")) {
                $recList = $news->field(array('id', 'title', 'title' => 'ftitle', 'addtime'))
                    ->where($map)
                    ->limit(8)
                    ->order('addtime DESC')
                    ->select();
                $mem->set("recList-$navid", $recList, MEMCACHE_COMPRESSED, 60);
            } else {
                $recList = $mem->get("recList-$navid");
            }

            $this->assign(array(
                'nav'=>$navName,
                'navlist'=>$navList,
                'reclist'=>$recList,
                'hotnews'=>$hotNews
            ));
            $this->display();
        }
    }
}